package com.itheima.controller;

import com.itheima.entity.ShoppingCart;
import com.itheima.service.ShoppingCartService;
import com.itheima.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;


    @PostMapping("/add")
    public R<Object> add(@RequestBody ShoppingCart shoppingCart, HttpServletRequest request){

        Long userId = (Long) request.getSession().getAttribute("user");
        shoppingCart.setUserId(userId); //设置当前用户id

        ShoppingCart add = shoppingCartService.add(shoppingCart);

        return  R.success(add);
    }
}
